package com.aaa.sbms.service;

import com.aaa.sbms.dao.CourseDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @FileName:CourseSeviceImpl
 * @Description:
 * @Author :99728
 * @Date: 2020/6/16 19:31
 * @Version:1.0.0
 */
@Service
public class CourseSeviceImpl  implements CourseService {

    @Autowired(required = false)
    private CourseDao courseDao;

    /**
     * 课程管理列表
     * @param map
     * @return
     */
    @Override
    public Map getPage(Map map) {
        //获取去输入值，计算后放入参数
        map.put("begin",(Integer.valueOf(map.get("pageNo")+"")-1)*Integer.valueOf(map.get("pageSize")+""));
        int pageSize = Integer.valueOf(map.get("pageSize").toString());
        map.put("pageSize",pageSize);
        //调用dao获取数据
        List<Map> page = courseDao.getPage(map);
        int total = courseDao.getPageCount(map);
        HashMap resultMap = new HashMap();
        resultMap.put("page",page);
        resultMap.put("total",total);
        return resultMap;
    }


    @Override
    public Map onelist(int courseid) {
        Map onelist = courseDao.onelist(courseid);
        HashMap<Object, Object> resultMap = new HashMap<>();
        resultMap.put("list",onelist);
        return resultMap;
    }

    @Override
    public int add(Map map) {
        return courseDao.add(map);
    }

    @Override
    public int update(Map map) {
        return courseDao.update(map);
    }

    @Override
    public int delete(int courseId) {
        return courseDao.delete(courseId);
    }
}
